<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      * {
        margin: 0;
        padding: 0;
      }
      img {
        display: block;
        margin: 0 auto;
      }
      .top {
        transition: height 1s;
        height: 0px;
        border-bottom: 2px solid red;
        background: #fff url('./images/top.png') top center no-repeat;
        position: fixed;
        width: 100%;
        top: 0;
        left: 0;
      }
    </style>
  </head>
  <body>
    <div class="top"></div>
    <img src="./images/jdbig.png" alt="" />
    <script>
      var div = document.querySelector('.top')
      window.onscroll = function () {
        // console.log(document.documentElement.scrollTop)
        var st = document.documentElement.scrollTop
        if (st > 300) {
          div.style.height = '50px'
          div.style.borderStyle = ''
        } else {
          div.style.height = ''
          div.style.borderStyle = 'none'
        }
      }
    </script>
  </body>
</html>
